package com.baizhi.service.impl;

import com.baizhi.entity.CmfzGuru;
import com.baizhi.mapper.CmfzGuruMapper;
import com.baizhi.service.CmfzGuruService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ljh
 * @since 2020-08-18
 */
@Service
public class CmfzGuruServiceImpl extends ServiceImpl<CmfzGuruMapper, CmfzGuru> implements CmfzGuruService {

    /**
     * 分页+姓名模糊查询
     * @param page
     * @param limit
     * @param key
     * @return
     */
    @Override
    public PageInfo<CmfzGuru> selectGuruByPageAndCondition(Integer page, Integer limit, String key) {
        PageHelper.startPage(page,limit);
        QueryWrapper<CmfzGuru> queryWrapper = new QueryWrapper<>();
        if (key!=null){
            queryWrapper.like("guru_name",key);
        }
        List<CmfzGuru> cmfzGurus = baseMapper.selectList(queryWrapper);
        return new PageInfo<>(cmfzGurus);
    }

    /**
     * 新增上师
     * @param cmfzGuru
     */
    @Override
    public void addGuru(CmfzGuru cmfzGuru) {
        baseMapper.insert(cmfzGuru);
    }

    /**
     * 修改状态
     * @param guruId
     * @param status
     */
    @Override
    public void updateGuruStatus(Integer guruId, Integer status) {
        CmfzGuru cmfzGuru = new CmfzGuru();
        cmfzGuru.setGuruStatus(status);
        cmfzGuru.setGuruId(guruId);
        baseMapper.updateById(cmfzGuru);
    }
}
